﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AxMSTSCLib;
using MessageBox = System.Windows.MessageBox;

namespace FDRemoteAssistant
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Init();
        }

        private AxMsRdpClient9 client;
        private void Init()
        {
            //AxRemoteDesktopClient client = new AxRemoteDesktopClient();
            client = new AxMsRdpClient9();
            //c.
            //c.Connect();
            //client.Settings.SetRdpProperty("Server", "192.168.1.174");
            //client.Settings.SetRdpProperty("UserName", "administrator");
            //client.Settings..SetRdpProperty("Server", "M8GaE2VN");
            //client.Settings.SetRdpProperty("Server", "M8GaE2VN");
            //client.Settings.SetRdpProperty("Domain", "192.168.1.174");
            var page = new TabPage();
            page.Text = client.Text;
            TabControl tcc = (TabControl) tcHost.Child;
            tcc.Dock = DockStyle.Fill;
            tcc.TabPages.Add(page);
            client.OnConnected += Client_OnConnected;
            client.OnDisconnected += Client_OnDisconnected;

            //var host = new WindowsFormsHost();
            //host.Child = client;

            //page.Controls.Add(host);
            page.Controls.Add(client);
            
        }

        private void Connect()
        {
            client.Server = "192.168.1.174";
            client.Domain = "192.168.1.174";
            client.UserName = "administrator";
            client.AdvancedSettings5.ClearTextPassword = "XSb123456";
            client.AdvancedSettings5.RedirectDrives = true;
            client.AdvancedSettings5.RedirectPrinters = true;
            client.Dock = DockStyle.Fill;
            client.Connect();
        }

        private void Client_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
        {
            MessageBox.Show("断开链接");

        }

        /*         
            rdpc.Server = parMachine.MachineName;
            rdpc.UserName = parMachine.UserName;
            rdpc.Domain = parMachine.DomainName;
            if (parMachine.Password != "")
            {
                rdpc.AdvancedSettings5.ClearTextPassword = parMachine.Password;
            }
            rdpc.AdvancedSettings5.RedirectDrives = parMachine.ShareDiskDrives;
            rdpc.AdvancedSettings5.RedirectPrinters = parMachine.SharePrinters;
            rdpc.ColorDepth = (int)parMachine.ColorDepth;
            rdpc.Dock = DockStyle.Fill;
         *
         */

        private void Client_OnDisconnected(object sender, IRemoteDesktopClientEvents_OnDisconnectedEvent e)
        {
            MessageBox.Show("断开链接");
        }

        private void Client_OnConnected(object sender, EventArgs e)
        {
            MessageBox.Show("连接成功");
        }

        private void BtnConnect_OnClick(object sender, RoutedEventArgs e)
        {
            Connect();
        }
    }
}
